from datetime import datetime
from typing import List, Optional

from fastapi_amis_admin.amis.components import ColumnImage, InputImage, InputRichText
from fastapi_amis_admin.models import ChoiceType,IntegerChoices,Field
from fastapi_user_auth.auth.models import User
from fastapi_user_auth.mixins.models import PkMixin
from sqlalchemy import Column, String, Text, select
from sqlalchemy.orm import Session
from sqlmodel import Relationship
from sqlmodelx import SQLModel


class TowerV1(PkMixin, table=True):
    __tablename__ = "tower_v1"#"铁塔V1"
    serial_number: Optional[int] = Field(title="序号",default=None)
    base_station_code: Optional[str] = Field(title="基站编码", default=None)
    town: Optional[str] = Field(title="镇区",default=None)
    area: Optional[str] = Field(title="片区",default=None)
    tower_name: Optional[str] = Field(title="铁塔站名", default=None)
    construction_name: Optional[str] = Field(title="建设站名", default=None)
    construction_type: Optional[str] = Field(title="建设类型",default=None)
    project_approval_code: Optional[str] = Field(title="立项编码", default=None)
    renovation_type: Optional[str] = Field(title="改造类型", default=None)
    is_joint_construction: Optional[str] = Field(title="是否共建", default=None)
    special_batch: Optional[str] = Field(title="专项批次",default=None)
    is_transform: Optional[str] = Field(
        title="是否改造转新建或新建转改造", default=None
    )
    attribute_change_date: Optional[str] = Field(title="属性变更日期", default=None)
    existing_operators: Optional[str] = Field(title="存量运营商",default=None)
    demanding_operators: Optional[str] = Field(title="需求运营商",default=None)
    mobile_planned_site_name: Optional[str] = Field(
        title="移动规划站点名称", default=None
    )
    mobile_demand_batch: Optional[str] = Field(title="移动需求批次",default=None)
    mobile_construction_attribute: Optional[str] = Field(
        title="移动建设属性",default=None
    )
    mobile_special_batch: Optional[str] = Field(title="移动专项批次",default=None)
    telecom_demand_batch: Optional[str] = Field(title="电信需求批次",default=None)
    telecom_planned_site_name: Optional[str] = Field(
        title="电信规划站点名称", default=None
    )
    unicom_demand_batch: Optional[str] = Field(title="联通需求批次",default=None)
    unicom_planned_site_name: Optional[str] = Field(
        title="联通规划站点名称", default=None
    )

    demand_longitude: Optional[str] = Field(title="需求规划经度",default=None)
    demand_latitude: Optional[str] = Field(title="需求规划纬度",default=None)
    actual_longitude: Optional[str] = Field(title="实际建设经度",default=None)
    actual_latitude: Optional[str] = Field(title="实际建设纬度",default=None)
    public_property_longitude: Optional[str] = Field(title="公共属性经度",default=None)
    public_property_latitude: Optional[str] = Field(title="公共属性纬度",default=None)
    detailed_address: Optional[str] = Field(title="详细地址",default=None)
    contact_person: Optional[str] = Field(title="谈点人及联系方式",default=None)
  

    # 允许通过英文属性名操作中文字段
    model_config = {"populate_by_name": True}

    # user: User = Relationship()

    # @staticmethod
    # def check_update_permission(session: Session, user: User, item_id: List[str]):
    #     # 管理员可以修改全部文章, 并且可以批量修改.
    #     if user.has_requires(session, roles=["admin"]):
    #         return True
    #     # 非管理员,只能修改自己的文章,并且不可批量修改.
    #     if len(item_id) > 1:
    #         return False
    #     stmt = select(1).where(Article.id == item_id[0], Article.user_id == user.id)
    #     return bool(session.scalar(stmt))



